home *** CD-ROM | disk | FTP | other *** search
-
- *** NOTE: The following code is only about 50% optimized.
-
-
- {..........................................................}
- PROCEDURE Draw_Screen_ASM (s_x, s_y, o_x, o_y : word;
- VAR shp_ptr, bshp_ptr, map, bmap, CT,
- FANM, BANM; bscroll : byte);
- VAR
- x, y : word;
- draw_x, draw_y : word;
- shape_offs : word;
- di_save : word;
- back_si_save : word;
- bo_x, bo_y : word;
- x_to_draw : word;
- x_to_skip : word;
- y_to_draw : word;
- y_skip_offs : word;
- ct_di_save : word;
-
- BEGIN
-
- ASM
- push ds
-
- mov [ct_di_save], 0
-
- les di, [screen]
- mov [di_save], di
-
- { Now we want to figure out background }
- { coords and offset of top left shape }
- { in background. }
- { This is a transformation of s_x, s_y }
- { into background coords...}
- { Once this is found, any other background }
- { shapes are merely offset from this...}
- mov ax, [s_x]
- mov bx, [s_y] { Get s_x, s_y * 32 to get world coords }
- shl ax, 5
- shl bx, 5
-
- sub ax, [o_x] { sub player offset from world coords }
- sub bx, [o_y]
-
- shr ax, 1 { Divide by 2 to get background world }
- shr bx, 1 { world coords...}
- push ax { Save coords...}
- push bx
-
- and ax, 31 { Get offset in shape to begin drawing }
- and bx, 31
- mov [bo_x], ax { Save offsets }
- mov [bo_y], bx
- pop bx { Restore background world coords }
- pop ax
-
- shr ax, 5 { Get background map coords of shape }
- shr bx, 5 { = world coords. / 32...}
-
- { Now, in ax is b_x, in bx is b_y...CONFUSING???}
-
- { Coords of top left shape in background }
- shl bx, 7 { Multiply ax(b_x) * 128(size of map x) }
- add bx, ax { Add in x coord to get full offset }
-
- mov [back_si_save], bx { Save in variable }
-
- { Now precalculate stuff for drawing background }
- { x_to_draw : 32 - bo_x...}
- { y_skip_offs : bo_y * 32...}
- { y_to_draw : 32 - bo_y...}
-
-
- cmp [bscroll], 0 { If non-scrolling background then }
- je @@FIGURE_STUFF { set background index to set point }
- { and make adjustments: }
- mov [back_si_save], 0
- mov ax, 31 { Since screen copied adjusted by values }
- mov bx, 31 { in o_x and o_y, we want to draw }
- sub ax, [o_x] { 32 - o_x OR o_y of background shape }
- sub bx, [o_y] { and then start drawing next shape, this }
- mov [bo_x], ax { will cause next shape to align with }
- mov [bo_y], bx { copying of screen, and in effect the }
- { background will not move!!! }
- cmp [bo_y], 32
- jne @@FIGURE_STUFF
- mov [bo_y], 0
-
- @@FIGURE_STUFF:
- mov ax, 32
- sub ax,[bo_x]
- mov [x_to_draw], ax
-
- mov bx, [bo_y]
- shl bx, 5
- mov [y_skip_offs], bx
-
- mov ax, 32
- sub ax, [bo_y]
- mov [y_to_draw], ax
-
- @@CONTINUE:
- lds si, [map]
- { Now get offset of top-left foreground shape.}
- mov ax, [s_y]
- shl ax, 7 { Mult. Y coord by 128, add X coord...}
- add ax, [s_x]
- add si, ax { Gives offset in Map of first square...}
-
- mov dh, 6 { dh is y counter for loop...}
-
- @@LOOP_Y:
- mov dl, 10 { dl is counter for x loop...}
-
- @@LOOP_X:
- mov [di_save], di { Save location in screen of top-left corner }
- { of current square..}
-
- xor ax, ax
- mov al, [si] { Get byte from Map... Square #...}
-
- {.................................................}
- { Now Check to see if Shape animating and if so }
- { draw the proper animation shape...}
- push ds
- push si
-
- lds si, [FANM] { Set pointer to Foreground anim data }
- mov bx, ax { Get shape number in bx }
- shl bx, 4 { Multiply bx by 16 to get proper row of data }
- { in Anim array...}
- add si, bx
-
- xor bx, bx
- mov bl, ds:[si] { Get byte of data from anim array }
- cmp bl, 255 { If CURRENT INDEX equals 255, then draw shape
- { as normally would...}
- je @@END_ANIM_CHECK
-
- add si, 3 { Move to first byte of anim pictures }
- add si, bx { Add CURRENT INDEX... }
-
- mov al, ds:[si] { Get proper shape number to draw...}
-
- @@END_ANIM_CHECK:
- pop si
- pop ds
- {.................................................}
-
- cmp al, 0
- jz @@DRAW_BACK { If Shape is ZERO, then square is }
- { transparent and we want background }
- { to show through, so jump to background }
- { drawing label...}
- cmp al, 30
- jae @@DRAW_BACK { ALSO, if shape => 32, then shape is either}
- { transparent and we need to draw }
- { background THEN foreground...OR shape needs}
- { to be drawn LAST, after all objects, etc..}
- { it is a shape which covers everything...}
-
- shl ax, 10 { Mul ax by 1024 to get Offset in Shape buffer.}
- { of shape we want to draw...}
- @@DRAW_FORE:
- (*****************************************************)
- push ds
- push si
-
- lds si, [shp_ptr]
- add si, ax { ax holds offset in shape buffer }
-
- cld { Increment }
- mov bx, 32d
-
- @@DRAW:
- mov cx, 16
- rep movsw
-
- add di, 288 { re-align di to next row }
-
- dec bx { Count down one row, check if }
- jnz @@DRAW { finished last row... }
-
- jmp @@END_DRAW
- (*****************************************************)
-
- @@DRAW_BACK:
- (*****************************************************)
- push ds
- push si
- push dx { Save DX also, may need it...}
- push ax { Save shape number that was in }
- { al, need it to find out if should }
- { draw transparent foreground...}
-
- lds si, [bmap] { Set pointer to background map }
- add si, [back_si_save]
-
- xor ax, ax
- mov al, ds:[si] { Get shape # in al }
- {.................................................}
- { Now Check to see if Shape animating and if so }
- { draw the proper animation shape...}
-
- lds si, [BANM] { Set pointer to Foreground anim data }
- mov bx, ax { Get shape number in bx }
- shl bx, 4 { Multiply bx by 16 to get proper row of data }
- { in Anim array...}
- add si, bx
-
- xor bx, bx
- mov bl, ds:[si] { Get byte of data from anim array }
- cmp bl, 255 { If CURRENT INDEX equals 255, then draw shape
- { as normally would...}
- je @@END_ANIM_CHECK1
-
- add si, 3 { Move to first byte of anim pictures }
- add si, bx { Add CURRENT INDEX... }
-
- mov al, ds:[si] { Get proper shape number to draw...}
-
- @@END_ANIM_CHECK1:
- {.................................................}
- shl ax, 10
-
- lds si, [bshp_ptr] { Set si to Shape buffer }
- add si, ax { Add offset of shape }
-
- add si, [y_skip_offs] { Offset based on Background Offset }
- add si, [bo_x] { Add x_to_skip to si }
-
- mov bx, [y_to_draw] { Number rows in bx }
-
- @@DRAW_1:
- mov cx, [x_to_draw] { Number of pixels x, in cx }
-
- rep movsb { Draw pixels !!! }
-
- add si, [bo_x]
- add di, 320
- sub di, [x_to_draw] { Skip down to next row }
-
- dec bx
- jnz @@DRAW_1 { loop!!!}
-
-
- @@CHECK_2:
- { IF we skipped part of top-left square, draw }
- { top part of square below it }
- cmp [bo_y], 0
- jz @@CHECK_3
-
- lds si, [bmap]
- add si, [back_si_save]
- add si, 128 { Down one row }
-
- xor ax, ax
- mov al, ds:[si]
- {.................................................}
- { Now Check to see if Shape animating and if so }
- { draw the proper animation shape...}
-
- lds si, [BANM] { Set pointer to Foreground anim data }
- mov bx, ax { Get shape number in bx }
- shl bx, 4 { Multiply bx by 16 to get proper row of data }
- { in Anim array...}
- add si, bx
-
- xor bx, bx
- mov bl, ds:[si] { Get byte of data from anim array }
- cmp bl, 255 { If CURRENT INDEX equals 255, then draw shape
- { as normally would...}
- je @@END_ANIM_CHECK2
-
- add si, 3 { Move to first byte of anim pictures }
- add si, bx { Add CURRENT INDEX... }
-
- mov al, ds:[si] { Get proper shape number to draw...}
-
- @@END_ANIM_CHECK2:
- {.................................................}
- shl ax, 10
-
- lds si, [bshp_ptr] { Set si to Shape buffer }
- add si, ax { Add offset of shape }
-
- add si, [bo_x] { Add x_to_skip to si }
-
- mov bx, [bo_y] { Number rows in bx }
-
- @@DRAW_2:
- mov cx, [x_to_draw] { Number of pixels x, in cx }
-
- rep movsb { Draw pixels !!! }
-
- add si, [bo_x]
- add di, 320
- sub di, [x_to_draw] { Skip down to next row }
-
- dec bx
- jnz @@DRAW_2
-
-
- @@CHECK_3:
- cmp [bo_x], 0
- jz @@DONE_CHECK
-
- mov di, [di_save]
- add di, 32
- sub di, [bo_x]
-
- lds si, [bmap]
- add si, [back_si_save]
- inc si { Over one column }
-
- xor ax, ax
- mov al, ds:[si]
- {.................................................}
- { Now Check to see if Shape animating and if so }
- { draw the proper animation shape...}
-
- lds si, [BANM] { Set pointer to Foreground anim data }
- mov bx, ax { Get shape number in bx }
- shl bx, 4 { Multiply bx by 16 to get proper row of data }
- { in Anim array...}
- add si, bx
-
- xor bx, bx
- mov bl, ds:[si] { Get byte of data from anim array }
- cmp bl, 255 { If CURRENT INDEX equals 255, then draw shape
- { as normally would...}
- je @@END_ANIM_CHECK3
-
- add si, 3 { Move to first byte of anim pictures }
- add si, bx { Add CURRENT INDEX... }
-
- mov al, ds:[si] { Get proper shape number to draw...}
-
- @@END_ANIM_CHECK3:
- {.................................................}
- shl ax, 10
-
- lds si, [bshp_ptr] { Set si to Shape buffer }
- add si, ax { Add offset of shape }
-
- add si, [y_skip_offs] { Offset based on Background Offset }
-
- mov bx, [y_to_draw] { Number rows in bx }
-
- @@DRAW_3:
- mov cx, [bo_x] { Number of pixels x, in cx }
-
- rep movsb { Draw pixels !!! }
-
- add si, [x_to_draw]
- add di, 320
- sub di, [bo_x] { Skip down to next row }
-
- dec bx
- jnz @@DRAW_3
-
-
- @@CHECK_4:
- { IF we skipped part of top-right square, draw }
- { top part of square below it }
- cmp [bo_y], 0
- je @@DONE_CHECK
-
- lds si, [bmap]
- add si, [back_si_save]
- add si, 129 { Down one row, over one column }
-
- xor ax, ax
- mov al, ds:[si]
- {.................................................}
- { Now Check to see if Shape animating and if so }
- { draw the proper animation shape...}
-
- lds si, [BANM] { Set pointer to Foreground anim data }
- mov bx, ax { Get shape number in bx }
- shl bx, 4 { Multiply bx by 16 to get proper row of data }
- { in Anim array...}
- add si, bx
-
- xor bx, bx
- mov bl, ds:[si] { Get byte of data from anim array }
- cmp bl, 255 { If CURRENT INDEX equals 255, then draw shape
- { as normally would...}
- je @@END_ANIM_CHECK4
-
- add si, 3 { Move to first byte of anim pictures }
- add si, bx { Add CURRENT INDEX... }
-
- mov al, ds:[si] { Get proper shape number to draw...}
-
- @@END_ANIM_CHECK4:
- {.................................................}
- shl ax, 10
-
- lds si, [bshp_ptr] { Set si to Shape buffer }
- add si, ax { Add offset of shape }
-
- mov bx, [bo_y] { Number rows in bx }
- @@DRAW_4:
- mov cx, [bo_x] { Number of pixels x, in cx }
-
- rep movsb { Draw pixels !!! }
-
- add si, [x_to_draw]
- add di, 320
- sub di, [bo_x] { Skip down to next row }
-
- dec bx
- jnz @@DRAW_4
-
-
- @@DONE_CHECK:
- pop ax { Restore Original foreground shape number...}
- pop dx
-
- (*****************************************************)
-
- cmp al, 30 { If shape # >= 32 < 48, draw compressed }
- jb @@END_DRAW { foreground shape..}
-
- cmp al, 48 { If it >= 48 then save it in a data structure}
- jb @@DRAW_TRANS { to draw later, after all objects/people drawn.}
-
- (*****************************************************)
- @@SAVE_DATA:
- { Save DI, Pic # in data structure to draw later }
- push es
- push bx
-
- les di, [CT]
- add di, [ct_di_save]
-
- mov es:[di], al { Save shape number }
- inc di
- mov bx, [di_save] { Save DI offset in ES to draw to }
- mov es:[di], bx
- inc di
- inc di
-
- add [ct_di_save], 3 { Save offset in data structure }
-
- pop bx
- pop es
- jmp @@END_DRAW
-
- (*****************************************************)
- @@DRAW_TRANS:
- shl ax, 10 { Mul by 1024 to get Offset in Shape buffer.}
-
- mov di, [di_save]
- lds si, [shp_ptr]
- add si, ax { ax holds offset }
-
- cld { Increment }
- mov bx, 32d { Do 32 rows...}
-
- @@GET_INFO:
- xor cx, cx
- mov cl, [si] { Read in byte from shape }
- inc si
-
- cmp cl, 0 { If zero then jump to add space }
- jz @@SKIP_PIXELS
-
- cmp cl, 255 { If 255, then want to go down to next row }
- je @@NEXT_ROW
- { Otherwise we want to draw pixels }
- rep movsb { Draw them }
- jmp @@GET_INFO
-
- @@SKIP_PIXELS:
- mov cl, [si]
- add di, cx
- inc si
- jmp @@GET_INFO
-
- @@NEXT_ROW:
- add di, 288 { re-align di to next row }
-
- dec bx { Count down one row, check if }
- jnz @@GET_INFO { finished last row... }
-
- (*****************************************************)
-
- @@END_DRAW:
-
- pop si
- pop ds
-
- mov di, [di_save] { Restore DI, increment by 32.. }
- add di, 32 { Move over 32 pixels for next shape...}
-
- inc si { Go to next square in Map...}
- inc [back_si_save] { Go to next square in background }
-
- dec dl { Subtract 1 from x loop counter.}
- jnz @@LOOP_X { Loop back...}
-
- @@FINISHED_X_LOOP:
- add si, 118 { Move down one row in map }
- add [back_si_save], 118 { Move down row in background }
-
- add di, 9920d { move DI down to next row on screen.}
-
- dec dh { Decrement y loop counter...}
- jnz @@LOOP_Y
-
- @@FINISHED_Y_LOOP:
- pop ds
- END;
-
- END;
- {..........................................................}
- PROCEDURE Draw_Close_Terrain (VAR Shp_Ptr, CT); Assembler;
- ASM
- push ds
-
- lds si, [CT] { Set pointer to data structure }
- les di, [screen]
-
- @@LOOP:
- xor ax, ax
- mov al, ds:[si] { Get Shape Number from Data Structure CT }
- cmp al, 0 { If zero then exit...done drawing }
- je @@END
-
- @@DRAW_SHAPE:
- inc si
- mov bx, ds:[si] { Get Offset to draw shape at }
- inc si
- inc si
-
- mov di, bx { Mov it into DI }
-
- push ds
- push si
- push bx
-
- cmp al, 54 { If is a transparent fore shape...}
- jae @@DRAW_TRANS
-
- { Draw Regular shape, no compression }
- (**************************************************)
- shl ax, 10
- lds si, [shp_ptr]
- add si, ax { ax holds offset in shape buffer }
-
- cld { Increment }
- mov bx, 32d
-
- @@DRAW:
- mov cx, 16
- rep movsw
-
- add di, 288 { re-align di to next row }
-
- dec bx { Count down one row, check if }
- jnz @@DRAW { finished last row... }
-
- pop bx
- pop si
- pop ds
- jmp @@LOOP
- (**************************************************)
-
- { Draw Shape with compression }
- (*****************************************************)
- @@DRAW_TRANS:
- shl ax, 10 { Mul by 1024 to get Offset in Shape buffer.}
- lds si, [shp_ptr]
- add si, ax { ax holds offset }
-
- cld { Increment }
- mov bx, 32d { Do 32 rows...}
-
- @@GET_INFO:
- xor cx, cx
- mov cl, [si] { Read in byte from shape }
- inc si
-
- cmp cl, 0 { If zero then jump to add space }
- jz @@SKIP_PIXELS
-
- cmp cl, 255 { If 255, then want to go down to next row }
- je @@NEXT_ROW
- { Otherwise we want to draw pixels }
- rep movsb { Draw them }
- jmp @@GET_INFO
-
- @@SKIP_PIXELS:
- mov cl, [si]
- add di, cx
- inc si
- jmp @@GET_INFO
-
- @@NEXT_ROW:
- add di, 288 { re-align di to next row }
-
- dec bx { Count down one row, check if }
- jnz @@GET_INFO { finished last row... }
-
- pop bx
- pop si
- pop ds
- jmp @@LOOP
- (*****************************************************)
-
-
- @@END:
- { Clear Data Structure }
- les di, [CT]
-
- mov ax, 0
- mov cx, 100
- rep stosw
-
- pop ds
- END;
- {............................................................................}
- PROCEDURE Process_Anim_Array (VAR Anm_Array); Assembler;
- ASM
- push ds
-
- lds si, [Anm_Array]
-
- xor dx, dx { Use dx as counter..to do all 64 shapes }
-
- @@LOOP:
- xor ax, ax
- mov al, ds:[si] { Check to see if first shape number }
- { is 255, if so then shape DOES NOT }
- { animate, so skip to next shape... }
- cmp al, 255
- je @@NEXT_SHAPE
-
- mov al, ds:[si+2] { Now find out if current_wait_time EQUALS zero }
- cmp al, 0 { If so, then increment index, check }
- jne @@DEC_WAIT_TIME
-
- xor bx, bx
- mov bl, ds:[si] { Get current index, increment it ...}
- inc bl
- mov ds:[si], bl { Moveback into current index }
- add si, bx
- { If the shape number at this new index }
- { is 255 then set index to ZERO, set }
- { current_wait_time to total_wait_time. }
- mov al, ds:[si+3]
- sub si, bx
- cmp al, 255
- jne @@SET_TIME
-
- mov al, 0 { Set current index to zero }
- mov ds:[si], al
-
- @@SET_TIME:
- mov al, ds:[si+1] { Set Current_wait_time }
- mov ds:[si+2], al
-
- jmp @@NEXT_SHAPE
-
- @@DEC_WAIT_TIME:
- dec al
- mov ds:[si+2], al
-
- @@NEXT_SHAPE:
- inc dx
- cmp dx, 64
- je @@END
-
- add si, 16
- jmp @@LOOP
-
- @@END:
- pop ds
-
- END;
- {..........................................................}
- PROCEDURE Copy_Part_Screen_Diff (x, y, sx, sy, x_size, y_size : word);
- Assembler;
- {
- X and Y hold the location in Display that image is to go to,
- and SX, SY hold location in Screen from which to draw..
- }
-
- ASM
- push ds
-
- mov dx, 03dah
- @@WAIT_VS1:
- in al, dx
- test al, 08h { Check vertical sync before continue.. }
- jz @@WAIT_VS1
-
- xor di,di
- mov ax,Video_mem
- mov es,ax
-
- lds si, [Screen]
-
- mov ax, [y] { Get row in y }
- mov bx, [y]
- shl ax, 8 { Shifts fast!!!}
- shl bx, 6
- add ax, bx
- mov [y], ax
-
- mov ax, [sy] { Get row from sy }
- mov bx, [sy]
- shl ax, 8 { Shifts fast!!!}
- shl bx, 6
- add ax, bx
- mov [sy], ax
-
- add di, [y] { Set di to proper offset row and }
- add si, [sy] { Set si to proper... }
-
- add di, [x] { proper off in that row... }
- add si, [sx]
-
- cld
-
- mov dx, [x_size] { dx holds # of bytes in x..}
- shr dx, 1d { get # of WORDS to process }
- mov bx, [y_size] { bx is counter for rows...}
-
- @@DRAW:
- mov cx, dx
- rep movsw
-
- @@NEXT:
- add si,320d
- add di,320d
- sub si,[x_size]
- sub di,[x_size]
-
- @@loop:
- dec bx
- jnz @@DRAW
-
- @@DONE:
-
- pop ds
- END;
- {.....................................................................}
- PROCEDURE Draw_People;
-
- VAR
- x,t : Integer;
- Objectnum : Integer;
- dx, dy : integer;
-
- BEGIN
- For Objectnum := 0 to Num_Of_Objects-1 DO
- BEGIN
- dy := py - (Screen_y shl 5);
- IF (dy >= 0) AND (dy < 160) THEN
- BEGIN
- dx := px - (Screen_x shl 5);
- IF (dx >= 0) AND (dx < 288) THEN
- Draw_Image_Screen_Tran (dx,dy,32,32,Player_Ptr^);
- END;
- END;
- END;
-
-
- **** The routine Draw_Image_Screen_Tran is just a transparent
- image drawing routine, that takes coords in vscreen,
- size, and a pointer to image data...
-
- {.....................................................................}
-